package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "商品基础属性接口")
@RestController
@RequestMapping("/admin/product")
public class BaseManageController {

    @Autowired
    private ManageService manageService;

    /**
     * 查询一级分类接口
     * @return
     */
    @GetMapping("/getCategory1")
    public Result getCategory1(){
        List<BaseCategory1> baseCategory1List = manageService.getCategory1();
        return Result.ok(baseCategory1List);
    }

    /**
     * 查询二级分类接口
     * @param categroy1Id
     * @return
     */
    @GetMapping("/getCategory2/{categroy1Id}")
    public Result getCategory2(@PathVariable("categroy1Id")String categroy1Id){
        List<BaseCategory2> baseCategory2List = manageService.getCategory2(categroy1Id);
        return Result.ok(baseCategory2List);
    }

    /**
     * 查询三级分类接口
     * @param category2Id
     * @return
     */
    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable("category2Id") String category2Id){
        List<BaseCategory3> category3List= manageService.getCategory3(category2Id);
        return Result.ok(category3List);
    }

    /**
     * 根据分类id查询平台属性接口列表
     * @param category1Id
     * @param category2Id
     * @param category3Id
     * @return
     */
    @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(@PathVariable("category1Id") String category1Id,
                               @PathVariable("category2Id") String category2Id,
                               @PathVariable("category3Id") String category3Id){
        List<BaseAttrInfo> attrInfoList = manageService.attrInfoList(category1Id,category2Id,category3Id);
        return Result.ok(attrInfoList);
    }

    @PostMapping("saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        manageService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    /**
     * 根据平台属性id，查询平台属性值列表接口
     * @param attrId
     * @return
     */
    @GetMapping("getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable("attrId")Long attrId){
        BaseAttrInfo baseAttrInfo = manageService.getAttrInfo(attrId);

        List<BaseAttrValue> attrValueList = baseAttrInfo.getAttrValueList();

        return Result.ok(attrValueList);
    }


    @GetMapping("/list/{page}/{limit}")
    public  Result index(@PathVariable Long page,
                         @PathVariable Long limit){

        Page<SkuInfo> skuInfoPage = new Page<>(page, limit);
        Page<SkuInfo> pageModel = manageService.getPage(skuInfoPage);
        return Result.ok(pageModel);
    }

    /**
     * 商品上架
     * @param skuId
     * @return
     */
    @GetMapping("onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId){
        manageService.onSale(skuId);
        return Result.ok();
    }

    @GetMapping("cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId){
        manageService.cancelSale(skuId);
        return Result.ok();
    }




}




